package com.xh3140.android.widget.dialog.view;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.xh3140.android.widget.dialog.params.HeaderParams;

/**
 * 对话框首部视图
 */
public class HeaderView extends LinearLayoutCompat {
    private final TitleView mTitleView;
    private final SubtitleView mSubtitleView;

    public HeaderView(@NonNull Context context) {
        this(context, new HeaderParams(context));
    }

    public HeaderView(@NonNull Context context, @NonNull HeaderParams params) {
        super(context);
        setOrientation(VERTICAL);
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        mTitleView = new TitleView(context, params.title);
        mSubtitleView = new SubtitleView(context, params.subtitle);
        addView(mTitleView);
        addView(mSubtitleView);
        if (mTitleView.getVisibility() == GONE && mSubtitleView.getVisibility() == GONE) {
            setVisibility(GONE);
        }
    }

    /**
     * 获取标题视图
     */
    public TitleView getTitleView() {
        return mTitleView;
    }

    /**
     * 获取副标题视图
     */
    public SubtitleView getSubtitleView() {
        return mSubtitleView;
    }

    /**
     * 配置视图
     *
     * @param params 首部视图配置属性
     */
    public void configView(@NonNull HeaderParams params) {
        mTitleView.configView(params.title);
        mSubtitleView.configView(params.subtitle);
        if (mTitleView.getVisibility() == GONE && mSubtitleView.getVisibility() == GONE) {
            setVisibility(GONE);
        }
    }
}
